import logging
from  config import Config as conf
import os
class Logging() :
    def __init__(self,level =10):
        self.logger = logging.getLogger('zrz_root')
        self.logger.setLevel(level)

#初始化日志
def loggUitl () :
    logger = Logging(conf.level).logger
    if logger.handlers:
        return logger
    fmt = logging.Formatter('%(asctime)s - [%(levelname)s] - %(filename)s[%(lineno)d]：%(message)s')
    file_handler = logging.FileHandler(filename=CreateDir(conf.base_home)+conf.log_filename,mode='a',encoding='utf-8')
    streamhandler = logging.StreamHandler()
    streamhandler.setFormatter(fmt)
    file_handler.setFormatter(fmt)
    logger.addHandler(file_handler)
    logger.addHandler(streamhandler)
    return logger


# 创建文件夹
def CreateDir(dir_path):
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
    return dir_path

if __name__ == '__main__':
    logger = loggUitl()
    for i in range(10):
        logger.info(i)